DZApp.service('orderReportSummaryService', function(commonService) {
	return {
		// 查询主服务
		queryMainSeviceSelect : function() {
			var url = "/operationService/listLevel1OrderServiceInfo";
			return commonService.commonAjaxByPost(url);
		},
		queryCardType : function() {
			var url = "/orderService/queryCardType";
			return commonService.commonAjaxByPost(url);
		},
		summaryReport : function() {
			var url = "/orderService/summaryReport";
			return commonService.commonAjaxByPost(url);
		},
		queryOrderSummaryReport : function(postData) {
			var url = "/orderService/queryOrderSummaryReport";
			return commonService.commonAjaxByPost(url,postData);
		}
	};
});
DZApp.controller('orderReportSummaryController', function($scope,
		orderReportSummaryService, $state) {
	$scope.orderSummaryModel = {};
	$scope.orderItemlist = {};
	$scope.queryMainSeviceSelect = {};
	$scope.queryCardType = {};
	$scope.query = {};
	$scope.isNeedConditionValidate = false;

	// 是否初始化的就查询
	var isQueryInit = true;
	if (isQueryInit) {
		// queryPagination(doParam());
	}
	orderReportSummaryService.queryMainSeviceSelect().then(function(data) {
		$scope.queryMainSeviceSelect = eval(data.bizData);
	});
	orderReportSummaryService.queryCardType().then(function(data) {
		$scope.queryCardType = eval(data.bizData);
	});
	$scope.ondatechange = function() {
		var startTime=$("#startTime").val();
		var endTime=$("#endTime").val();
		if( startTime!=''&& endTime==''){
			$("#endTime").val( startTime);
			return;
		}
		if( startTime==''&& endTime!=''){
			$("#startTime").val( endTime);
			return;
		}
		if( startTime> endTime){
			$("#startTime").val( endTime);
			$("#endTime").val( startTime);
			return;
		}
//		if($scope.orderSummaryModel.startTime<$scope.orderSummaryModel.endTime){
//			$("#endTime").val($scope.orderSummaryModel.startTime);
//			console.log(3);
//		}
	}
	$scope.summaryReport=function() {
		orderReportSummaryService.summaryReport().then(function() {
			$scope.queryOrderSummaryReport();
		});
	}
	$scope.queryOrderSummaryReport = function() {
		var param=($.param($scope.orderSummaryModel));
		orderReportSummaryService.queryOrderSummaryReport(param).then(function(data) {
			var list = eval(data.bizData);
			var dates=[];
			var prices=[];
			var nums=[];
			for (index in list){
				dates[index]=list[index].date_m.trim();
				nums[index]=list[index].num;
				prices[index]=list[index].price;
			}
			$(function () {
			    $('#container').highcharts({
			        title: {
			            text: '汇总报表',
			            x: -20 //center
			        },
			       
			        xAxis: {
			            categories: dates
			        },
			        yAxis: {
			            title: {
			                text: '金额/数量'
			            },
			            plotLines: [{
			                value: 0,
			                width: 1,
			                color: '#808080'
			            }]
			        },
			        credits: {
			            enabled:false
			            },
			        legend: {
			            layout: 'vertical',
			            align: 'right',
			            verticalAlign: 'middle',
			            borderWidth: 0
			        },
			        series: [{
					            name: '金额(￥)',
					            data: prices
					        },{
					            name: '数量(单)',
					            data: nums
					        }]
			    });
			});

		});
	}
	//懒加载,解决highcharts多次加载报错问题
	jQuery.getScript("/static/common/highcharts/highcharts.js").done(function() {
		 jQuery.getScript("/static/common/highcharts/modules/exporting.js").done(function() {
	        	$scope.queryOrderSummaryReport();
	    })
	}).fail(function() {
		 $scope.queryOrderSummaryReport();
	});
	
});
